// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   periodFinish_ok.java

package finance.account;

import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class periodFinish_ok extends HttpServlet
{

	public periodFinish_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		HttpSession session = request.getSession();
		nseer_db_backup1 finance_db = new nseer_db_backup1(dbApplication);
		try
		{
			String account_period = request.getParameter("account_period");
			String account_finished_time = request.getParameter("timea");
			if (finance_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String sql = (new StringBuilder("select * from finance_voucher where check_tag='0' and account_period='")).append(account_period).append("'").toString();
				ResultSet rs = finance_db.executeQuery(sql);
				if (!rs.next())
				{
					sql = (new StringBuilder("select * from finance_voucher where check_tag='1' and account_tag='0' and account_period='")).append(account_period).append("'").toString();
					rs = finance_db.executeQuery(sql);
					if (!rs.next())
					{
						sql = (new StringBuilder("select * from finance_voucher where account_tag='1' and profit_or_cost='0' and cost_tag='0' and account_period='")).append(account_period).append("'").toString();
						rs = finance_db.executeQuery(sql);
						if (!rs.next())
						{
							sql = (new StringBuilder("select * from finance_voucher where account_tag='1' and (profit_or_cost='1' or profit_or_cost='0') and profit_tag='0' and account_period='")).append(account_period).append("'").toString();
							rs = finance_db.executeQuery(sql);
							if (!rs.next())
							{
								sql = (new StringBuilder("update finance_account_period set account_finished_tag='1',account_finished_time='")).append(account_finished_time).append("' where account_period='").append(account_period).append("'").toString();
								finance_db.executeUpdate(sql);
								response.sendRedirect("finance/account/periodFinish_ok_a.jsp");
							} else
							{
								response.sendRedirect("finance/account/periodFinish.jsp");
							}
						} else
						{
							response.sendRedirect("finance/account/periodFinish.jsp");
						}
					} else
					{
						response.sendRedirect("finance/account/periodFinish.jsp");
					}
				} else
				{
					response.sendRedirect("finance/account/periodFinish.jsp");
				}
				finance_db.commit();
				finance_db.close();
			} else
			{
				response.sendRedirect("/error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
